package basic;

/**
 * @Author: 海琳琦
 * @Date: 2021/8/31 14:13
 */
public class Title53_rework {
    public static void main(String[] args) {
        int[] a ={-2,-1,-3,-4,-1,-2,-1,-5,-4};
        System.out.println(maxSubArray(a));
    }
    private static int maxSubArray(int[] nums) {
        int max=(int)-1e5-1,sum;
        for (int i = 0; i < nums.length;i++) {
            sum=0;
            for (int j = i; j < nums.length; j++) {
                sum+=nums[j];
                if(sum>=max){
                    max = sum;
                }
                if(sum<=0){
                    i=j;
                    break;
                }
            }
        }
        return max;
    }
}
